package nju.mscs.businesslogic;

import java.util.Iterator;

import nju.mscs.data.object.*;
import nju.mscs.server.businessLogic.Controller;

public class SC implements SearchController{
	Database db;
	public SC(){
		db=LogIn.db;
	}
	
	public String[] searchVIP(String one,String two){
		VipConsumer vip=null;
		if(!one.equals("")){
			vip=db.searchVipConsumerById(one);
		}
		else if(!two.equals(""))
			vip=db.searchVipConsumerByTelephone(Integer.parseInt(two.trim()));
		if(vip!=null){
		String sex=null;
		if(vip.getSex()==VipConsumer.MALE)
			sex="男";
		else
			sex="女";
		String time=vip.getBirth().getYear()+"."+vip.getBirth().getMonth()+"."+vip.getBirth().getDate();
		System.out.println(time);
		String[] result={vip.getId()+"",vip.getTelephone()+"",vip.getName(),sex,time,vip.getSumPoints()+"",""};//得到restTime
		System.out.println("\n\n"+"   "+result[0]+result[1]+result[2]);
		return result;
		}
		else
		return null;
	}

	
	public String[][] getUserList() {
		// TODO Auto-generated method stub
		Iterator<User> it=db.getUserList();
		int n=db.getAmountOfUser();
		String[][] result=new String[n][4];
		for(int i=0;i<n;i++){
			User user=it.next();
			result[i][0]=user.getId();
			result[i][1]=user.getName();
			result[i][3]=user.getPassword();
			String type=null;
			if(user.CASHIER==user.getType())
				type="收银员";
			else if(user.SHOP_MANAGER==user.getType())
				type="分店经理";
			else if(user.GENERAL_MANAGER==user.getType())
				type="总经理";
			if(user.SYSTEM_MANAGER==user.getType())
				type="系统管理员";
			result[i][2]=type;
		}
		return result;
	}

	@Override
	public String[][] getGoodsList() {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String[][] getGiftList() {
		// TODO Auto-generated method stub
		Iterator<Gift> ig=db.getGiftList();
		int n=0;
		while(ig.hasNext()){
			ig.next();
			n++;
		}
		ig=db.getGiftList();
		int i=0;
		String[][] result=new String[n][2];
		while(ig.hasNext()){
			Gift gift=ig.next();
			result[i][0]=gift.getId();
			result[i][1]=gift.getName();
			i++;
		}
		return result;
	}
	@Override
	public String[] getGoods(String id) {
		// TODO Auto-generated method stub
		Goods good=db.searchGoodsById(id);
		String[] result=null;
		if(good!=null){
			result=new String[4];
			result[0]=good.getId();
			result[1]=good.getName();
			result[2]=good.getPrice()+"";
			result[3]=good.getAmount()+"";
		}
		return result;
	}
}
